package com.egg.ylt.Utils;

import android.content.Context;
import android.os.CountDownTimer;
import android.widget.TextView;

import com.egg.ylt.R;


/**
 * Created by sichaoqi on 2018/10/13.
 */

public class TimeCountUtil extends CountDownTimer{
    /**
     * @param millisInFuture    The number of millis in the future from the call
     *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
     *                          is called.
     * @param countDownInterval The interval along the way to receive
     *                          {@link #onTick(long)} callbacks.
     */
    private TextView mTextView;
    private Context mContext;

    public TimeCountUtil(long millisInFuture, long countDownInterval, Context context, TextView textView) {
        super(millisInFuture, countDownInterval);
        this.mTextView = textView;
        this.mContext = context;
    }

    @Override
    public void onTick(long millisUntilFinished) {
        mTextView.setClickable(false);
        mTextView.setText("重新发送验证码(" + (millisUntilFinished / 1000) + ")");
        mTextView.setTextColor(mContext.getResources().getColor(R.color.color_666666));
    }

    @Override
    public void onFinish() {
        mTextView.setText("重新发送验证码");
        mTextView.setClickable(true);
        mTextView.setTextColor(mContext.getResources().getColor(R.color.color_008ADE));
    }
}
